package selenium;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestOne {
	public static void main(String [] args) throws InterruptedException, IOException {
		String driverPath = System.getProperty("user.dir")+"/seleniumTest/chromeDriver/geckodriver.exe";
		System.setProperty("webdriver.gecko.driver", driverPath);
		WebDriver driver = new FirefoxDriver();
		driver.get("http://103.120.226.190/selenium-demo/git-repo");
		File data = new File("E:\\软件工程\\软件测试\\Selenium\\data.txt");
		String usernameXPath = "/html/body/div/div/div/div/div/div/div[2]/div/form/div[1]/input";
		String passwordXPath = "/html/body/div/div/div/div/div/div/div[2]/div/form/div[2]/input";
		String queryXPath = "/html/body/div/div/div/div/div/div/div[2]/div/form/div[3]/input";
		String answerXPath = "/html/body/div/div/div/div/div/div/div[2]/div/form/div[4]/code";
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(data)));
		String line = "";
		int k = 0;
		while((line = br.readLine()) != null && !line.isEmpty()) {
			String[] strs = line.split(" ");
			driver.findElement(By.xpath(usernameXPath)).sendKeys(strs[0]);
			driver.findElement(By.xpath(passwordXPath)).sendKeys(strs[1]);
			driver.findElement(By.xpath(queryXPath)).click();
			String ans = driver.findElement(By.xpath(answerXPath)).getAttribute("innerHTML");
			if(ans.equals("user number and password don't match!")) {
				System.out.println("第"+ ++k + "行账号与密码不匹配");
			}else {
				System.out.println("第"+ ++k + "行测试成功");
			}
		}
		br.close();
		driver.close();
	}
}